package com.dl.DaoImpl;

import com.dl.Bean.Customer;
import com.dl.Dao.CustomerDao;
import com.dl.util.DBConnection;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class CustomerDaoImpl implements CustomerDao {

        private Connection conn = null ;

        private PreparedStatement pstmt = null ;
        @Override
        public void add(Customer cs) {
            DBConnection dbc = new DBConnection() ;
            conn = dbc.getConnection() ;
            try {
                pstmt = conn.prepareStatement("insert into customer(name,password,phonenumber,idcard,email) values(?,?,?,?,?)") ;

                System.out.println("插入数据中...");pstmt.setString(1, cs.getName()) ;
                pstmt.setString(2, cs.getPassword()) ;
                pstmt.setString(3, cs.getPhonenumber()) ;
                pstmt.setString(4, cs.getIdcard()) ;
                pstmt.setString(5, cs.getEmail()) ;
                System.out.println(cs.getName()+cs.getPassword());

                pstmt.executeUpdate();
               // conn.commit();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally {
                dbc.AllClose();
            }
        }


}
